﻿using OS.Infrastructure.Domain;

namespace TaskKernel.Domain
{
    public class DepartmentUser : AbstractEntity
    {
        public DepartmentUser()
        {
        }

        public DepartmentUser(Department department, Account user, RoleEnum role) : this()
        {
            Department = department;
            User = user;
            Role = role;
        }

        public virtual Department Department { get; set; }
        public virtual Account User { get; set; }
        public virtual RoleEnum Role { get; set; }

        public virtual bool IsAdminOrExecutor
        {
            get { return Role == RoleEnum.Admin || Role == RoleEnum.Executor ; }
        }

        public virtual bool IsParticipantDepartment
        {
            get { return Role == RoleEnum.Participant; }
        }

        public override int GetHashCode()
        {
            int hashCode = 0;
            if (Department == null || User == null)
                return hashCode ^ UID.GetHashCode();
            return hashCode ^ Department.UID.GetHashCode() ^ User.UID.GetHashCode() ^
                   Role.ToDescriptionString().GetHashCode();
        }

        public override bool Equals(object obj)
        {
            var toCompare = obj as DepartmentUser;
            if (toCompare == null)
                return false;
            return (GetHashCode() == toCompare.GetHashCode());
        }
    }
}